package com.example.demo.ai.llm.service;

import com.jfinal.kit.Kv;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.flow.ChainContext;
import org.noear.solon.flow.FlowEngine;

/**
 * @author airhead
 */
@Component
public class LlmDiagService {
  @Inject private FlowEngine flowEngine;

  public Kv diag(String prompt) {
    try {
      ChainContext chainContext = new ChainContext();
      chainContext.put("prompt", prompt);
      Kv kv = Kv.create();
      chainContext.put("result", kv);
      flowEngine.eval("ai-flow-01", chainContext);

      return kv;
    } catch (Throwable e) {
      throw new RuntimeException(e);
    }
  }
}
